#include <iostream>
#include <sys/epoll.h>
#include<unistd.h>
#include<string>

class Epoller
{
    static const int size = 124;

public:
    Epoller()
    {
        _epfd = epoll_create(size);
        if (_epfd == -1)
        {
            std::cout << "create epoll false" << std::endl;
        }
    }

    bool Epoll_ctl(int op, int sock, uint32_t event)
    {
        int n=0;
        if (op == EPOLL_CTL_DEL)
        {
            n = epoll_ctl(_epfd, op, sock, nullptr);
            if (n != 0)
            {
                std::cout << "epoll delete false" << std::endl;
            }
        }
        else
        {
            struct epoll_event ev;
            ev.data.fd = sock;
            ev.events = event;
            int n = epoll_ctl(_epfd, op, sock, &ev);
            if (n != 0)
            {
                std::cout << "epoll up false" << std::endl;
            }
        }
        return n;
    }

    int Epoll_wait(struct epoll_event revents[], int num)
    {
        int n = epoll_wait(_epfd, revents, num, _timeout);
        return n;
    }

    ~Epoller()
    {
        if(_epfd>0) close(_epfd);
    }

private:
    int _epfd;
    int _timeout = 3000;
};